<template>
    <div class="organization-list">
        <div><TissueTree ref="TissueTree" v-on:tissueIdla="tissueIdla"></TissueTree></div>
        <div class="organization-content-list">
            <div class="content-cotent">
                <div class="content-title">
                    <div class="title">{{queryStructsInfo.name}}</div>
                    <div>类型：{{queryStructsInfotype}}</div>
                    <div>商品：{{queryStructsInfo.productsCount}}</div>
                    <div>经纪人：{{queryStructsInfo.agentsCount}}</div>
                </div>
                <div class="cotent-botton">
                    <div class="cotent-botton-input">
                        <el-input
                                placeholder="请输入组织名称"
                                v-model="value1"
                                clearable>
                        </el-input>
                    </div>
                    <div class="cotent-botton-input">
                        <el-select v-model="value2" clearable placeholder="请选择类型">
                            <el-option
                                    v-for="item in options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                    <div class="cotent-botton-input">
                        <el-select v-model="value3" clearable placeholder="是否启用">
                            <el-option
                                    v-for="item in options1"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                    <div class="cotent-botton-botton-one" @click="queryInfo">查 询</div>
                    <div class="cotent-botton-botton-two" @click="emptyingInfo">清 空</div>
                </div>
                <div class="cotent-botton">
                    <div class="cotent-botton-botton-one" @click="addDetails">
                        新增
                    </div>
                    <div class="cotent-botton-botton-two" @click="deletDetails">删 除</div>
                    <div class="cotent-botton-botton-two" @click="operationDetails(1)">启 用</div>
                    <div class="cotent-botton-botton-two" @click="operationDetails(0)">禁 用</div>
                    <div class="cotent-botton-botton-two2" @click="distributionShow">
                        分配楼盘
                    </div>
                    <div class="cotent-botton-botton-two2" @click="importUsers">批量导入组织</div>
                </div>
                <UserList :headlist="headlist" :contentlist="list" @selectList="selectList"></UserList>
                <Pagination :totalpag="totalpag" v-on:currentpage="currentpage"></Pagination>
            </div>

        </div>
        <addForm  :dialogFormVisible="showDetails" @close="closeForm" @refreshTree="refreshTree" @refreshList="getlist"></addForm>
        <distributionProperties  :dialogFormVisible="distributionShowaddhouse" @close="closeForm" :organizationIds="selectLists"></distributionProperties>
        <importStructs :dialogFormVisible="dialogFormVisibleimport" @close="closeFormImport"  @refreshList="getlist"></importStructs>
    </div>
</template>

<script>
    import TissueTree from '../common/TissueTree';
    import UserList from '../common/user/UserList';
    import Pagination from '../common/Pagination';
    import importStructs from '../common/Dialog/importStructs';
    import addForm from '../common/Dialog/addForm';
    import distributionProperties from '../common/Dialog/distributionProperties';
    import {isUseAble,organType} from "../../utils/constant"
    export default {
        name: "structManage",
        data(){
            return{
                dialogFormVisibleimport:false,
                distributionShowaddhouse:false,
                organizationId: this.$store.getters.userData.userMsg.id,//组织id
                queryStructsInfo:{},
                queryStructsInfotype:"",
                parentId:1,
                value1:"",
                value2:"",
                value3:"",
                totalpag:0,
                current:1,
                selectLists:"",
                showDetails:false,
                headlist:{
                   checkout:true,
                   operation:{
                       type:true,
                       fromurl:"structManage",
                   },
                   list:[
                    {
                        prop:"id",
                        label:"序号",
                        width:"80",
                    },{
                        prop:"name",
                        label:"组织名称",
                        width:"200",
                    },{
                        prop:"type",
                        label:"类型",
                        width:"130",
                       formatter:function(row, column, cellValue, index){
                           return organType(row.type)
                       }
                    }
                    ,{
                        prop:"productsCount",
                        label:"商品",
                        width:"80",
                    }
                    ,{
                        prop:"agentsCount",
                        label:"经纪人",
                        width:"120",
                    }
                    ,{
                        prop:"lastUpdate",
                        label:"更新人",
                        width:"120",
                    }
                    ,{
                        prop:"lastUpdateTime",
                        label:"更新时间",
                        width:"160",
                    }
                    ,{
                        prop:"usable",
                        label:"是否启用",
                        width:"160",
                       formatter:function(row, column, cellValue, index){
                           return isUseAble(row.usable)
                       }
                    }
                ]},
                list:[],
                options: [{
                    value: '0',
                    label: '代理商'
                }, {
                    value: '1',
                    label: '开发商'
                }, {
                    value: '2',
                    label: '平台'
                }, {
                    value: '3',
                    label: '中介'
                }, {
                    value: '4',
                    label: '职能部门'
                }],
                options1:[{
                    value: '1',
                    label: '已启用'
                },{
                    value: '0',
                    label: '已停用'
                }],
            }
        },
        components: {
            TissueTree,
            UserList,
            Pagination,
            addForm,
            distributionProperties,
            importStructs
        },
        mounted(){
        this.getlist();
        },
        methods: {
            refreshTree() {
                this.$refs.TissueTree.initTreeInfo();
            },
                //批量导入用户
            importUsers(){
                this.dialogFormVisibleimport=true
            },
            closeFormImport(){
                this.dialogFormVisibleimport=false
            },
            distributionShow(){
                this.distributionShowaddhouse=true
            },
            //查询
            queryInfo(){
                if (this.value1==""&&this.value2==""&&this.value3=="") {
                    this.$message({
                        message: '没有输入或选择查询内容',
                        type: 'warning'
                    });
                }else {
                    this.getlist()
                }
            },
            //清空
            emptyingInfo(){
                this.value1="";
                this.value2="";
                this.value3="";
                this.getlist();
            },
            //删除
            selectList(val){
                this.selectLists=val
            },
            deletDetails(){
                if(this.selectLists){
                    this.$confirm('确定要删除内容吗？', '确认', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                    }).then(() => {
                        let _this = this;
                        let params={
                            ids:this.selectLists,
                        }
                        console.log("ssssssssssssssssssssss",this.selectLists)
                        _this.Api.setting.deleteStruct(params).then((data)=>{
                            console.log("aaaaaaaaaaaaaaa",data)
                            if(data.returnCode==10000){
                                this.getlist()
                                //刷新左侧树
                                this.$refs.TissueTree.initTreeInfo();
                                this.$message({
                                    type: 'success',
                                    message: '删除成功!'
                                });
                            }else {
                                this.$message({
                                    type: 'warning',
                                    message: data.msg
                                });
                            }

                        })
                    }).catch(() => {

                    });

                }else {
                    this.$alert('您还没勾选删除内容', '温馨提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            this.$message({
                                type: 'info',
                                message: `action: ${ action }`
                            });
                        }
                    });
                }
                console.log("删除的",this.selectLists)
            },
            //启用，禁用
            operationDetails(type){
                if (type==1) {
                    var msg1="您还没勾选启用内容"
                    var msg2="启用"
                }else {
                    var msg1="您还没勾选禁用内容"
                    var msg2="禁用"
                }
                if(this.selectLists){
                    this.$confirm('此操作将'+msg2+'该内容, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        let _this = this;
                        let params={
                            ids:this.selectLists,
                            type:type
                        }
                        console.log("ssssssssssssssssssssss",this.selectLists)
                        _this.Api.setting.batchUpdateStruct(params).then((data)=>{
                            if(data.returnCode==10000){
                                this.getlist()
                                this.$message({
                                    type: 'success',
                                    message: msg2+'成功!'
                                });
                            }else {
                                this.$message({
                                    type: 'warning',
                                    message: data.msg
                                });
                            }

                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
                }else {
                    this.$alert(msg1, '温馨提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            this.$message({
                                type: 'info',
                                message: `action: ${ action }`
                            });
                        }
                    });
                }
            },
            addDetails(){
                this.showDetails=true
            },
            closeForm(){
                this.showDetails=false;
                this.distributionShowaddhouse=false
            },
            currentpage(currentpage){
                console.log("当前页1111111111，",currentpage)
                this.current=currentpage
                this.getlist();
            },
            tissueIdla(val){
                this.organizationId=val;//获取组织id
                this.getlist();
                console.log("memememeemggggggggggggggg",val)
            },
            getlist(){
                let _this = this;
                let params={
                    current:_this.current,
                    size:10,
                    parentId:this.organizationId,
                    usable:this.value3,
                    type:this.value2,
                    name:this.value1,
                }
                console.log("pppppppppppppppppppp",params)
                _this.Api.setting.queryStructs(params).then((data)=>{
                    console.log("aaaaaaaaaaaaaaa",data)
                    _this.totalpag=data.data.page.total;
                    _this.list=data.data.page.records;
                    _this.queryStructsInfo=data.data;
                    _this.queryStructsInfotype=organType(data.data.type)
                })
            }

        }
    }
</script>

<style scoped rel="stylesheet/scss" lang="scss">
.organization-list{
    display: flex;
    .organization-content-list{
        margin: 20px;
        .content-cotent{
            background-color: #ffffff;
            padding: 24px 32px;
            .content-title{
                display: flex;
                margin-bottom: 24px;
                div{
                    font-size:14px;
                    font-family:PingFangSC-Regular;
                    font-weight:400;
                    color:rgba(51,51,51,0.85);
                    line-height:22px;
                    margin-right: 16px;
                }
                .title{
                    font-size:20px;
                    font-family:PingFangSC-Medium;
                    font-weight:500;
                    color:rgba(0,0,0,0.85);
                }
            }
        }
        .cotent-botton{
            display: flex;
            margin-bottom: 24px;
            .cotent-botton-input{
                width:200px;
                height:32px;
                margin-right: 16px;

            }
            .cotent-botton-botton-one{
                width:65px;
                height:32px;
                line-height: 32px;
                text-align: center;
                background:rgba(24,144,255,1);
                border-radius:4px;
                font-size:14px;
                font-family:PingFangSC-Regular;
                font-weight:400;
                color:rgba(255,255,255,1);
                margin-right: 16px;
                cursor: pointer;
            }
            .cotent-botton-botton-two{
                width:65px;
                height:32px;
                line-height: 32px;
                background:rgba(255,255,255,1);
                border-radius:4px;
                border:1px #D9D9D9 solid;
                font-size:14px;
                font-family:PingFangSC-Regular;
                font-weight:400;
                color:rgba(0,0,0,0.65);
                text-align: center;
                margin-right: 16px;
                cursor: pointer;
            }
            .cotent-botton-botton-two2{
                padding: 0px 16px;
                height:32px;
                line-height: 32px;
                background:rgba(255,255,255,1);
                border-radius:4px;
                border:1px #D9D9D9 solid;
                font-size:14px;
                font-family:PingFangSC-Regular;
                font-weight:400;
                color:rgba(0,0,0,0.65);
                text-align: center;
                margin-right: 16px;
                cursor: pointer;
            }
        }
    }
}
</style>